<?php

namespace app\agent\controller;

use think\facade\Db;

class Controller extends \app\BaseController
{
    protected $agent = null;

    protected function initialize()
    {

        $agent = \app\common\facade\auth\Auth::attempt(request()->all());

        if (empty($agent)) {
            $this->showError('登录已过期，请重新登录！');
        }
        if ($agent['status'] != 1) {
            $this->showError('账号被禁用');
        }

        $this->agent = $agent;
    }

    private function showError($message)
    {
        exit(json_encode([
            'code' => 401,
            'message' => $message,
            'data' => [],
        ], JSON_UNESCAPED_UNICODE));
    }
}
